<template>
  <div class="login-panel">
    <h1 class="title">后台管理系统</h1>
    <!--中间tabs切换 -->
    <div class="tabs">
      <el-tabs type="border-card" stretch v-model="activeName">
        <el-tab-pane label="账号登录" name="account">
          <!-- 图标 -->
          <template #label>
            <div class="label">
              <el-icon><UserFilled /></el-icon>
              <span class="text">账号登录</span>
            </div>
          </template>
          <!--  -->
          <pane-account ref="accountRef"></pane-account>
        </el-tab-pane>
        <el-tab-pane label="手机登录" name="phone">
          <!-- 图标 -->
          <template #label>
            <div class="label">
              <el-icon><Iphone /></el-icon>
              <span class="text">手机登录</span>
            </div>
          </template>
          <pane-phone></pane-phone>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!-- 记住密码 -->
    <div class="controls">
      <el-checkbox v-model="remPassword" label="记住密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>
    <el-button type="primary" class="login-btn" @click="handleLoginBtnClick"
      >立即登录</el-button
    >
  </div>
</template>

<script setup lang="ts">
import { localCache } from "@/utils/cache"
import PaneAccount from "./pane-account.vue"
import PanePhone from "./pane-phone.vue"
import { ref, watch } from "vue"
const remPassword = ref<boolean>(localCache.getCache("remPassword") ?? false)
const activeName = ref("account")
const accountRef = ref<InstanceType<typeof PaneAccount>>()
watch(remPassword, (newValue) => {
  localCache.setCache("remPassword", newValue)
})
function handleLoginBtnClick() {
  if (activeName.value === "account") {
    //  console.log(accountRef.value?.LoginAction().name)
    accountRef.value?.LoginAction(remPassword.value)
  } else {
    console.log("手机登录")
  }
  // console.log(activeName.value)
}
</script>
<style scoped lang="less">
.login-panel {
  width: 330px;
  margin-bottom: 150px;

  .title {
    text-align: center;
    margin-bottom: 15px;
  }

  .label {
    display: flex;
    align-items: center;
    justify-content: center;

    .text {
      margin-left: 5px;
    }
  }

  .controls {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
  }

  .login-btn {
    margin-top: 10px;
    width: 100%;
    // --el-button-size: 50px;
  }
}
</style>
